﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat-Html5</title>
</head>
<body>
    <input type="button" value="从左至右" onclick="javascript:changeSplitLayout('lefttoright');" />
    <input type="button" value="从上至下" onclick="javascript:changeSplitLayout('toptobottom');" />
    <input type="button" value="从右至左" onclick="javascript:changeSplitLayout('righttoleft');" />
    <input type="button" value="从下至上" onclick="javascript:changeSplitLayout('bottomtotop');" />
    <input type="button" value="绝对值" onclick="javascript:changeSplitMode('absolutesize');" />
    <input type="button" value="百分比" onclick="javascript:changeSplitMode('percentsize');" /><br />
    <canvas id="splitCanvas" width="800" height="800" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvasSplit = document.getElementById("splitCanvas"); //绘图区域
        canvasSplit.width = window.innerWidth;
        canvasSplit.height = window.innerHeight;
        let paintSplit = new FCPaint(); //绘图对象
        paintSplit.canvas = canvasSplit;
        scaleCanvas(paintSplit);
        //判断主题色
        paintSplit.defaultUIStyle = "dark";
        let url = location.href;
        if (url.indexOf("color=light") != -1) {
            paintSplit.defaultUIStyle = "light";
        }
        //判断是否移动端
        paintSplit.isMobile = isMobileMode();
        if (paintSplit.isMobile) {
            paintSplit.scaleFactorX = 2.5;
            paintSplit.scaleFactorY = 2.5;
        }

        //创建图层
        let split = new FCSplitLayoutDiv();
        let splitter = new FCView();

        //初始化图层
        let initDiv = function () {
            split.dock = "fill";
            split.size = new FCSize(400, 400);
            addView(split, paintSplit);
            if (split.paint.defaultUIStyle == "dark") {
                split.backColor = "rgb(0,0,0)";
                split.borderColor = "rgb(100,100,100)";
                split.textColor = "rgb(255,255,255)";
            } else if (split.paint.defaultUIStyle == "light") {
                split.backColor = "rgb(255,255,255)";
                split.borderColor = "rgb(150,150,150)";
                split.textColor = "rgb(0,0,0)";
            }

            if (split.paint.defaultUIStyle == "dark") {
                splitter.backColor = "rgb(150,150,150)";
            } else if (split.paint.defaultUIStyle == "light") {
                splitter.backColor = "rgb(100,100,100)";
            }
            addViewToParent(splitter, split);
            split.splitter = splitter;
            splitter.location = new FCPoint(200, 0);
            splitter.size = new FCSize(5, 100);
            splitter.paint = paintSplit;
            splitter.allowDrag = true;

            let firstView = new FCView();
            firstView.backColor = "rgb(255,0,0)";
            firstView.location = new FCPoint(0, 0);
            firstView.size = new FCSize(0, 0);
            firstView.viewName = "firstview";
            addViewToParent(firstView, split);
            split.firstView = firstView;

            let secondView = new FCView();
            secondView.backColor = "rgb(0,255,0)";
            secondView.location = new FCPoint(0, 0);
            secondView.size = new FCSize(0, 0);
            secondView.viewName = "secondview";
            addViewToParent(secondView, split);
            split.secondView = secondView;
            split.oldSize = new FCSize(400, 400);
            resetSplitLayoutDiv(split);
        };

        initDiv();

        /*
        * 点击方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        * clicks:点击次数
        */
        let onClick_Split = function (view, firstTouch, firstPoint, secondTouch, secondPoint, clicks) {
            onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks);
        };


        /*
        * 鼠标按下实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseDown_Split = function (view, mp, buttons, clicks, delta) {
            onMouseDownDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 鼠标滚动实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseWheel_Split = function (view, mp, buttons, clicks, delta) {
            if (window.event.ctrlKey && view.paint) {
                //放大显示
                if (delta < 0) {
                    view.paint.scaleFactorX = view.paint.scaleFactorX + 0.1;
                    view.paint.scaleFactorY = view.paint.scaleFactorY + 0.1;
                    resizeAll();
                    //缩小显示
                } else if (delta > 0) {
                    if (view.paint.scaleFactorX > 0.2) {
                        view.paint.scaleFactorX = view.paint.scaleFactorX - 0.1;
                        view.paint.scaleFactorY = view.paint.scaleFactorY - 0.1;
                        resizeAll();
                    }
                }
                return;
            }
            onMouseWheelDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 触摸开始方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchBegin_Split = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchBeginDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 触摸移动方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchMove_Split = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchMoveDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 触摸结束方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchEnd_Split = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchEndDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 鼠标移动实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseMove_Split = function (view, mp, buttons, clicks, delta) {
            onMouseMoveDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 鼠标抬起实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseUp_Split = function (view, mp, buttons, clicks, delta) {
            onMouseUpDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 重绘背景的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        paintSplit.onPaint = function (view, paint, clipRect) {
            onPaintDefault(view, paint, clipRect);
        };

        /*
        * 重绘边框的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        paintSplit.onPaintBorder = function (view, paint, clipRect) {
            onPaintBorderDefault(view, paint, clipRect);
        };

        /*
        * 更新布局的实现方法
        * views:视图集合
         */
        paintSplit.onUpdateView = function (views) {
            updateViewDefault(views);
        }

        //注册事件
        addMouseDownEvent(canvasSplit, paintSplit, onMouseDown_Split);
        addMouseMoveEvent(canvasSplit, paintSplit, onMouseMove_Split);
        addMouseWheelEvent(canvasSplit, paintSplit, onMouseWheel_Split);
        addMouseUpEvent(canvasSplit, paintSplit, onMouseUp_Split, onClick_Split);
        addTouchBeginEvent(canvasSplit, paintSplit, onTouchBegin_Split);
        addTouchMoveEvent(canvasSplit, paintSplit, onTouchMove_Split);
        addTouchEndEvent(canvasSplit, paintSplit, onTouchEnd_Split, onClick_Split);

        /*
         * 重置大小
         */
        let resizeAll = function () {
            canvasSplit.width = document.documentElement.clientWidth;
            canvasSplit.height = document.documentElement.clientHeight;
            scaleCanvas(paintSplit);
            updateViewDefault(paintSplit.views);
            invalidate(paintSplit);

        };

        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };
        updateViewDefault(paintSplit.views);
        invalidate(paintSplit);

        /*
        * 切换布局
        * mode:布局方式
        */
        let changeSplitLayout = function (layout) {
            split.layoutStyle = layout;
            if (layout == "lefttoright") {
                if (split.splitMode == "percentsize") {
                    splitter.location = new FCPoint(canvasSizeSplit.cx / 2, 0);
                } else {
                    splitter.location = new FCPoint(200, 0);
                }
                splitter.size = new FCSize(5, canvasSizeSplit.cy);
            } else if (layout == "righttoleft") {
                if (split.splitMode == "percentsize") {
                    splitter.location = new FCPoint(canvasSizeSplit.cx / 2, 0);
                } else {
                    splitter.location = new FCPoint(canvasSizeSplit.cx - 200, 0);
                }
                splitter.size = new FCSize(5, canvasSizeSplit.cy);
            } else if (layout == "toptobottom") {
                if (split.splitMode == "percentsize") {
                    splitter.location = new FCPoint(0, canvasSizeSplit.cy / 2);
                } else {
                    splitter.location = new FCPoint(0, 200);
                }
                splitter.size = new FCSize(canvasSizeSplit.cx, 5);
            } else if (layout == "bottomtotop") {
                if (split.splitMode == "percentsize") {
                    splitter.location = new FCPoint(0, canvasSizeSplit.cy / 2);
                } else {
                    splitter.location = new FCPoint(0, canvasSizeSplit.cy - 200);
                }
                splitter.size = new FCSize(canvasSizeSplit.cx, 5);
            }
            resetSplitLayoutDiv(split);
            invalidate(paintSplit);
        };

        /*
        * 切换模式
        */
        let changeSplitMode = function (mode) {
            split.splitMode = mode;
            split.splitPercent = -1;
            changeSplitLayout(split.layoutStyle);
        };
    </script>
</body>
</html>
